package com.oauth.logging;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * Logger class used to abstract different logging providers . Currently it is
 * using java.util.Logging.
 * 
 * @author asanthan
 * 
 */
public class Log4jLogger implements RapwavesLogger {
	private Logger mLogger;

	private Log4jLogger(Logger pLogger) {
		mLogger = pLogger;
	}

	public static Log4jLogger getLogger(String pName) {
		return new Log4jLogger(Logger.getLogger(pName));
	}

	public static <T> Log4jLogger getLogger(Class<T> pClass) {
		return getLogger(pClass.getName());
	}

	public void info(String pMessage) {
		mLogger.info(pMessage);
	}

	public void debug(String pMessage) {
		mLogger.debug(pMessage);
	}

	public void error(String pMessage) {
		mLogger.log(Level.ERROR, pMessage);
	}

	public void error(String pMessage, Throwable pThrown) {
		mLogger.log(Level.ERROR, pMessage, pThrown);
	}

	public void entering(String pSourceClass, String pSourceMethod) {
		mLogger.trace(String.format("Entered Class:%s Method:%s", pSourceClass, pSourceMethod));
	}

	public void throwing(String pSourceClass, String pSourceMethod, Throwable pThrown) {
		mLogger.trace(String.format("Entered Class:%s Method:%s", pSourceClass, pSourceMethod),
				pThrown);
	}
}
